<!DOCTYPE html>
<html>
  <head>
    <title>Transition Group Demo</title>
    <style>
      .list-item {
        display: inline-block;
        margin-right: 10px;
      }
      .list-enter-active,
      .list-leave-active {
        transition: all 0.5s;
      }
      .list-enter, .list-leave-to /* .list-leave-active for v2.1.8+ */ {
        opacity: 0;
        transform: translateY(30px);
      }
    </style>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <button @click="add">Add</button>
      <button @click="remove">Remove</button>
      <transition-group name="list" tag="p">
        <span v-for="item in items" :key="item" class="list-item">
          {{ item }}
        </span>
      </transition-group>
    </div>

    <script>
      new Vue({
        el: "#app",
        data: {
          items: [1, 2, 3, 4, 5],
          nextNum: 6,
        },
        methods: {
          randomIndex() {
            return Math.floor(Math.random() * this.items.length);
          },
          add() {
            this.items.splice(this.randomIndex(), 0, this.nextNum++);
          },
          remove() {
            this.items.splice(this.randomIndex(), 1);
          },
        },
      });
    </script>
  </body>
</html>
